package com.atguigu.gmall.alipay;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 李旭
 * @Time: 10:09
 * @Description:
 *
 *  测试支付宝对外暴露的接口是否正确
 */
public class AlipayDemo {



    public static void main(String[] args) throws Exception{
        //支付宝的支付客户端
        AlipayClient alipayClient = new DefaultAlipayClient(
                "https://openapi.alipaydev.com/gateway.do",
                "2016102100732915",
                "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDDQeCa63yt/0szYYmu3qmstmBCvIpsk2BGKlCSDuu6vSE+qaBTpab1auwTT/OxkiCF3p7bGDHiTIHRZoQnJtMlG/UZ6O+ssBE1SCOoO+geq9xU1J3vQLP6CI98ZcjGolUypwXQhkqhhHVtX8dCTYR75NfnOikVpsTdiWdKFftLgd1X9U+46jBDUQ/ehrjrAz31e5PeVAAPo/d/4ILoNIKyAm+Ix8GHjpf5avbG2dPHOKfMnT8V2uQAKBBATJjkHTHa9XbYNb814ne+GmyI6P4pTZ6coBM4PsY6R8qmdy9UPNoo3290bNAV+CredJiGOnO16/muYekmQlFAwnhj9HWrAgMBAAECggEBAKZj9SsPkegUrdjTPakvRhhQMies06lCzb/9Pzu4S1mO4k2r71xYxbZNr2+lql2f0OdDlsvOCnR2DgqL+gIDK9trv6qcveHDCGcHWpt6sYuxmMkRhqTj1nsz4FJ5yma63y+S9XmFdwO9BPR3si3mMQgDM5lwDqLMwuamuMaBhOwJ+F4K+5uglAUDKzQFAn+jW4EuX5nmR/g6EfbUs9NEaIUVjC6j3LBewNds8jR8Mem6wcursPd9NYYkiOVRxe3qlE8dl5I78Q72NXklZJaefdpbD/Q7IQItMhKVO3ezcTIja96sX1UowcuvE17GX+/bv7tCVec+8URT0RSf67h1h8ECgYEA8wCCNlIPnJH0eY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61qmz/o9lw+hRq6KBfdktl4xm0d5f+uMgCLKqa6bYbFyG7vNZszGJ6yW2n6fFbZ0B4PgPXfrRFVG+OS204bi7sGDba6DuJPPuk8B/gkVoDkmKHNRnLXZi74jyZROlEXKr8JElZqpT6RODkKAmIRCGlQrAadUntgmymguRlN2K+TfSNIigY1FRekb/BudYhlbA5QIDAQAB",
                "RSA2");

        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

        Map<String,String> param = new HashMap<>();
        param.put("out_trade_no","dfzbdggfdrytyyyumdfithjtyyygt");
        param.put("product_code","FAST_INSTANT_TRADE_PAY");
        param.put("total_amount","123.09");
        param.put("subject","为了测试付钱");

        request.setBizContent(JSONObject.toJSONString(param));
        AlipayTradePagePayResponse response = alipayClient.pageExecute(request);
        if(response.isSuccess()){
            System.out.println(response.getBody());
            System.out.println("调用成功");

            /**
             * <form name="punchout_form" method="post" action="https://openapi.alipaydev.com/gateway.do?charset=UTF-8&method=alipay.trade.page.pay&sign=Ei50SGC43K6AZoTiZvu039yb%2FWVyBATOqQC1ODnZSwWHz6LXtrg2Mq876rtAQd5fPbsykmaGeFGI0xtqKb2AW8AwnUh1wEA8PP4Bvas9VjRJkdHdW3V6PsbkrCy3Y%2BZ5bpe2xLPw%2B%2FUUi4WK6%2BNrJaqVMobZLGzuLbDR5E54sqA%2BuPaBUOSTAeXlGNgWLCHFPQ48XOcBiMi%2B%2FMmlwdHUqnz%2BVYsFdPUojeXeZgi%2Bt5BNJmKqH3MGOY%2FB68wLxBG%2BK9sBIXH6ZRHStrFYpaF9j7Y16CNdCUjBpCAY4ZmIqk9lrr0%2F470AWSeR9BoWYfjJqyhTGNfekAQ782Fn2mmFgw%3D%3D&version=1.0&app_id=2016102100732915&sign_type=RSA2&timestamp=2021-05-27+11%3A13%3A53&alipay_sdk=alipay-sdk-java-4.8.73.ALL&format=json">
             * <input type="hidden" name="biz_content" value="{&quot;out_trade_no&quot;:&quot;dfzbdggfdrytyyyumdfithjtyyygt&quot;,&quot;total_amount&quot;:&quot;123.09&quot;,&quot;subject&quot;:&quot;为了测试付钱&quot;,&quot;product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}">
             * <input type="submit" value="立即支付" style="display:none" >
             * </form>
             * <script>document.forms[0].submit();</script>
             * 调用成功
             */
        } else {
            System.out.println("调用失败");
        }
    }
}
